from flask import Blueprint, current_app, make_response, request
from flask import Blueprint


class NestableBlueprint(Blueprint):
    def register_blueprint(self, blueprint, **options):
        def deferred(state):
            url_prefix = (state.url_prefix or u"") + (options.get('url_prefix', blueprint.url_prefix) or u"")
            if 'url_prefix' in options:
                del options['url_prefix']
            state.app.register_blueprint(blueprint, url_prefix=url_prefix, **options)

        self.record(deferred)

api = NestableBlueprint('api_1_0', __name__, url_prefix='/api/v1.0')

user = Blueprint('/api/v1.0/users',__name__)
right = Blueprint('/api/v1.0/rights',__name__)
role = Blueprint('/api/v1.0/roles',__name__)
good = Blueprint('/api/v1.0/goods',__name__)
order = Blueprint('/api/v1.0/orders',__name__)
report = Blueprint('/api/v1.0/reports',__name__)
categorie = Blueprint('/api/v1.0/categories',__name__)
api.register_blueprint(user,url_prefix='/users')
api.register_blueprint(right,url_prefix='/rights')
api.register_blueprint(role,url_prefix='/roles')
api.register_blueprint(categorie,url_prefix='/categories')
api.register_blueprint(good,url_prefix='/goods')
api.register_blueprint(order,url_prefix='/orders')
api.register_blueprint(report,url_prefix='/reports')
from . import passport, menu, users,rights,roles,categories,goods,orders,reports
